/*
 * @Author: zhangguliu1234 984556209@.com
 * @Date: 2023-11-16 15:02:55
 * @LastEditors: zhangguliu1234 984556209@.com
 * @LastEditTime: 2024-01-18 23:05:47
 * @FilePath: \sample_project\components\key.c
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */

#include "key.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#define ggpio_0 0
void key_init(void)
{
    gpio_reset_pin(GPIO_NUM_0);
    gpio_config_t gpio_0 = {};
    gpio_0.pin_bit_mask = 1ULL << ggpio_0;
    gpio_0.mode = GPIO_MODE_INPUT;
    gpio_config(&gpio_0);
}

int key_press(void)
{
    // 0--按下，1--松手
    if (gpio_get_level(GPIO_NUM_0) == 0)
    {
        // syy_delay_25();
        vTaskDelay(5);
        if (gpio_get_level(GPIO_NUM_0) == 0)
        {
            while (!gpio_get_level(GPIO_NUM_0))
            {
            }
            return 0;
        }
    }
    return 1;
}
